//
//  FeedViewController.m
//  DialectShare
//
//  Created by timmy zhong on 3/20/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "FeedsViewController.h"
#import "User.h"
#import "LoginViewController.h"
#import "DialectProxy.h"
#import "DialectDB.h"
#import "Const.h"
#import "ListenViewController.h"

@interface FeedsViewController ()
- (void)refresh;
@end

@implementation FeedsViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"刷新" style:UIBarButtonItemStylePlain target:self action:@selector(refresh)] autorelease];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if ([User current] == nil) {
        
        LoginViewController *loginController = [[LoginViewController alloc] init];
        [self presentModalViewController:loginController animated:YES];
        [loginController release];
        
        return ;
    }
    
    [self.proxy feeds];
    
}

- (NSArray *)getDialects
{
    return [self.db feedsFromStart:0 count:1000];
}

- (void)refresh
{
    [self.proxy feeds];
}

@end
